<?php
/*
+ --------------------------------------------------- +
|  Ineo Article Manager - Version 1.x
|  Copyright 2006-2007, Dan Cryer and William McGann
+ --------------------------------------------------- +

Ineo Article Manager is free software; you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as published by
the Free Software Foundation.

Ineo Article Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Ineo; see the file License.txt.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/

$queries = array
(
	//----
	// Create Tables:
	//----
	
	"CREATE TABLE ibf_ams_articles (
	  article_id mediumint(9) NOT NULL auto_increment,
	  article_title varchar(250) NOT NULL default '',
	  article_description varchar(75) NOT NULL default '',
	  article_content mediumint(9) NOT NULL default '0',
	  article_author varchar(32) NOT NULL default '',
	  article_created_date int(10) NOT NULL default '0',
	  article_edited_by varchar(32) NOT NULL default '',
	  article_edited_date int(10) NOT NULL default '0',
	  article_cats text NOT NULL,
	  article_tid int(10) NOT NULL default '0',
	  article_views int(11) NOT NULL default '0',
	  article_revisions int(11) NOT NULL default '1',
	  article_is_queued tinyint(1) NOT NULL default '0',
	  article_links text,
	  article_cat_id int(11) NOT NULL default '0',
	  UNIQUE KEY article_id (article_id),
	  KEY article_cat_id (article_cat_id),
	  KEY article_revisions (article_revisions),
	  KEY article_is_queued (article_is_queued),
	  KEY article_content (article_content)
	)",

	"CREATE TABLE ibf_ams_attachments (
	  attach_id int(11) NOT NULL auto_increment,
	  attach_ext varchar(10) NOT NULL default '',
	  attach_file varchar(250) NOT NULL default '',
	  attach_location varchar(250) NOT NULL default '',
	  attach_article varchar(32) NOT NULL default '0',
	  attach_mid mediumint(8) NOT NULL default '0',
	  attach_size int(10) NOT NULL default '0',
	  attach_isimage tinyint(1) NOT NULL default '0',
	  UNIQUE KEY attach_id (attach_id),
	  KEY attach_article (attach_article)
	)",

	"CREATE TABLE ibf_ams_categories (
	  category_id int(11) NOT NULL auto_increment,
	  category_name varchar(255) NOT NULL default '',
	  category_desc varchar(255) NOT NULL default '',
	  category_parent int(11) NOT NULL default '0',
	  category_order  int(11) NOT NULL default '0',
	  UNIQUE KEY category_id (category_id),
	  KEY category_parent (category_parent)
	)",

	"CREATE TABLE ibf_ams_content (
	  content_id mediumint(9) NOT NULL auto_increment,
	  content_article int(11) NOT NULL default '0',
	  content_author varchar(32) NOT NULL default '',
	  content_date int(10) NOT NULL default '0',
	  content_content mediumtext NOT NULL,
	  content_is_queued tinyint(1) NOT NULL default '0',
	  UNIQUE KEY content_id (content_id),
	  KEY content_article (content_article),
	  KEY content_is_queued (content_is_queued),
	  KEY content_author (content_author)
	)",

	"CREATE TABLE ibf_ams_logs (
	  id bigint(20) NOT NULL auto_increment,
	  act varchar(255) NOT NULL default '',
	  code varchar(255) NOT NULL default '',
	  note text NOT NULL,
	  member_id int(10) NOT NULL default '0',
	  time int(10) NOT NULL default '0',
	  ip_address varchar(255) NOT NULL default '',
	  UNIQUE KEY id (id)
	)",

	"CREATE TABLE ibf_ams_upgrade_history (
	  ams_upgrade_id int(10) NOT NULL auto_increment,
	  ams_version_id int(10) NOT NULL default '0',
	  ams_version_human varchar(200) NOT NULL default '',
	  ams_upgrade_date int(10) NOT NULL default '0',
	  ams_upgrade_mid int(10) NOT NULL default '0',
	  ams_upgrade_notes text NOT NULL,
	  PRIMARY KEY  (ams_upgrade_id)
	)",

	"CREATE TABLE ibf_ams_watchlists (
	  watch_user int(11) NOT NULL default '0',
	  watch_id int(11) NOT NULL default '0',
	  watch_type tinyint(4) NOT NULL default '0',
	  KEY watch_user (watch_user),
	  KEY watch_id (watch_id)
	)",

	"CREATE TABLE ibf_ams_rating (
	  rate_mid mediumint(9) NOT NULL default '0',
	  rate_rating tinyint(1) NOT NULL default '0',
	  rate_artid mediumint(9) NOT NULL default '0',
	  KEY rate_artid (rate_artid)
	)",
	
	//----
	// Alter Existing Tables:
	//----

	"ALTER TABLE ibf_groups ADD g_ams_view TINYINT(1) NOT NULL",
	"ALTER TABLE ibf_groups ADD g_ams_add TINYINT(1) NOT NULL",
	"ALTER TABLE ibf_groups ADD g_ams_edit TINYINT(1) NOT NULL",
	"ALTER TABLE ibf_groups ADD g_ams_upload TINYINT(1) NOT NULL",
	"ALTER TABLE ibf_groups ADD g_ams_ismod TINYINT(1) NOT NULL",
	"ALTER TABLE ibf_groups ADD g_ams_queue TINYINT(1) NOT NULL",
	
	//----
	// Insert some data:
	//----
	
	"INSERT INTO ibf_ams_categories ( category_name , category_desc , category_parent ) VALUES ( 'Demo Category' , 'This is an example category.' , 0 )",
	"INSERT INTO ibf_ams_articles ( article_title , article_description , article_content , article_author , article_created_date , article_edited_date , article_cats , article_is_queued , article_cat_id ) VALUES ( 'Demo Article' , 'A demonstration article.' , 1 , 'Ineo' , UNIX_TIMESTAMP() , UNIX_TIMESTAMP() , '' , 0 , 1 )",

	"INSERT INTO ibf_ams_content ( content_article , content_author , content_date , content_content , content_is_queued ) VALUES ( 1 , 'Ineo' , UNIX_TIMESTAMP() , 'This is a demonstration article. It has no content.' , 0 )",
	
	"INSERT INTO ibf_ams_upgrade_history ( ams_version_id , ams_version_human , ams_upgrade_date , ams_upgrade_mid ) VALUES ( '10001', '1.0.1', UNIX_TIMESTAMP(), {$this->installer->ipsclass->member['id']} )",

	//----
	// Update Existing Data
	//----
	
	"UPDATE ibf_groups SET g_ams_view = 1",
	"UPDATE ibf_groups SET g_ams_add  = 1",
	"UPDATE ibf_groups SET g_ams_edit = 1 WHERE g_access_cp = 1 OR g_is_supmod = 1",
	"UPDATE ibf_groups SET g_ams_upload = 1 WHERE g_access_cp = 1 OR g_is_supmod = 1 OR g_can_msg_attach = 1",
	"UPDATE ibf_groups SET g_ams_ismod = 1 WHERE g_access_cp = 1 OR g_is_supmod = 1",
	"UPDATE ibf_groups SET g_ams_queue = 1 WHERE g_access_cp = 1 OR g_is_supmod = 1",
		
);

//----
// Add Fulltext Indexes:
//----
if( $this->installer->ipsclass->DB->sql_can_fulltext() )
{
	$queries[] = "alter table ibf_ams_content ADD FULLTEXT( content_content )";
}

?>